﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xos_http.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __DATA_STRUCT_COOKIE_H__
#define __DATA_STRUCT_COOKIE_H__

#include "../tools/head.h"

namespace xos_http
{
    class session;

    class cookie : public xos_stl::mem_item< xos::release_impl< cookie >, thread_lock, thread_lock >,
        public xos_http::i_cookie
    {
    public:
        typedef xos::release_impl< cookie > T;

    public:
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
        static int get_addr( POOL *** pppPool, LIST *** pppList );
        static int load( const char * lpszCookie, xos_box::i_list * pCookieList, session ** ppv );

    public:
        cookie();
        ~cookie();

    public:
        std::string m_comment;
        std::string m_domain;
        std::string m_value;
        std::string m_name;
        std::string m_path;
        bool m_secure;
        int m_age;
        int m_ver;
        std::string m_cookie;

    protected:
        int fmt( char * pBuf, int & nLen, int & nPos, const std::string & name, const std::string & value );
        int fmt( char * pBuf, int & nLen, int & nPos, const std::string & name, bool value );
        int fmt( char * pBuf, int & nLen, int & nPos, const std::string & name, int value );
        int init_data();

    public:
        int serial();
        int init();
        int term();

        // 
        // i_cookie method
        // 
    public:
        const char * comment( const char * lpszComment );
        const char * domain( const char * lpszDomain );
        const char * value( const char * lpszValue );
        const char * name( const char * lpszName );
        const char * path( const char * lpszPath );

        bool secure( bool bSecure, bool bSet );
        int version( int nVer, bool bSet );
        int age( int nAge, bool bSet );
        
    };

} // xos_http

#endif // __DATA_STRUCT_COOKIE_H__
